package fun.rockchen.service.concreteService;

import fun.rockchen.bean.*;
import fun.rockchen.dao.StatisticsDao;
import fun.rockchen.service.interfaceService.StatisticsService;
import fun.rockchen.utils.responseUtils.ResponseJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Rock Chen
 * @Description:
 * @date 2023/10/21 20:10
 */

@Service
public class StatisticsServiceImpl implements StatisticsService {
    private final StatisticsDao statisticsDao;

    @Autowired
    public StatisticsServiceImpl(StatisticsDao statisticsDao) {
        this.statisticsDao = statisticsDao;
    }

    @Override
    public ResponseEntity<?> getTypeList(String id) {
        List<TypeStatisticsEntity> list = statisticsDao.getTypeList(id);
        return ResponseEntity.ok(ResponseJson.getSuccess(list));
    }

    @Override
    public ResponseEntity<?> getTypeListInSevenDay(String id) {
        List<TypeDayEntity> list = statisticsDao.getTypeListInSevenDay(id);
        return ResponseEntity.ok(ResponseJson.getSuccess(list));
    }

    @Override
    public ResponseEntity<?> getTypeListDay(TypeDayParamEntity typeDayParamEntity) {
        List<TypeDayEntity> list = statisticsDao.getTypeListDay(typeDayParamEntity);
        return ResponseEntity.ok(ResponseJson.getSuccess(list));
    }

    @Override
    public ResponseEntity<?> getTaskTime(TaskTotalTimeParam taskTotalTimeParam) {
        List<TaskTotalTimeEntity> list = statisticsDao.getTaskTime(taskTotalTimeParam);
        if (list.isEmpty()) {
            return ResponseEntity.ok(ResponseJson.NoData());
        } else {
            for (TaskTotalTimeEntity taskTotalTimeEntity : list) {
                double time = taskTotalTimeEntity.getTotal();
                double hour = time / 3600;
                System.out.println("time: " + time);
                System.out.println("hour: " + hour);
                System.out.println();
                taskTotalTimeEntity.setTotal(hour);
            }
            return ResponseEntity.ok(ResponseJson.getSuccess(list));
        }
    }

    @Override
    public ResponseEntity<?> getTag(String userId) {
        List<TagStatisticsEntity> tagStatisticsEntityList = statisticsDao.getTag(userId);
        if (!tagStatisticsEntityList.isEmpty()) {
            return ResponseEntity.ok(ResponseJson.getSuccess(tagStatisticsEntityList));
        }
        return ResponseEntity.ok(ResponseJson.getError());
    }
}
